package com.blog.service.impl;

import com.blog.entity.Article;
import com.blog.service.AsyncArticleSyncService;
import com.blog.utils.ArticleSearchUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

@Slf4j
@Service
public class AsyncArticleSyncServiceImpl implements AsyncArticleSyncService {

    private final ExecutorService executorService;
    private final ArticleSearchUtils articleSearchUtils;

    public AsyncArticleSyncServiceImpl(ExecutorService executorService,ArticleSearchUtils articleSearchUtils) {

        this.executorService = executorService;
        this.articleSearchUtils = articleSearchUtils;
    }

    @Override
    public Future<?> syncBatchToEs(List<Article> batch) {
        return executorService.submit(() -> {
            try{
                log.info("开始同步{}条数据",batch.size());
//                articleSearchUtils.saveArticles(batch);

            } catch (Exception e) {
                log.error("同步数据失败:{}",e.getMessage());
            }
        });
    }
}
